<?php

	/* dependence */
	CoreProject::Using('core.constans');

	/* timezone fix code */
	if (function_exists('date_default_timezone_set'))
	{
		@date_default_timezone_set(CPR_CURRENT_TIMEZONE);
	}

	/**
	 * @package		CoreProject
	 * @author		Usenko Timur V. [RayMan]
	 */
	class CoreProject
	{
		const NAME = 'Core Project';
		const VERSION = '1.0.3';

		private function __construct() {}
		
		/**
		 * @param	string	$_classToUse
		 * @return	bool
		 */
		public static function Using($_classToUse)
		{
			static $_classesArray = array();
			if (isset($_classesArray[$_classToUse]))
			{
				return true;
			}
			
			if (preg_match('/[a-z.\-]/', $_classToUse))
			{
				$_classFile = preg_replace('/[\.]+/', '.', $_classToUse);
				$_classFile = self::RootPath().str_replace('.', '/', $_classFile).'.php';
				$_classFile = str_replace('\\', '/', $_classFile);
				if (file_exists($_classFile))
				{
					if (include $_classFile)
					{
						$_classesArray[$_classToUse] = true;
						return true;
					}
				}
				else
				{
					self::_coreError('package "'.$_classToUse.'" dosn\'t exist. ['.$_classFile.']');
				}
			}

			self::_coreError('package "'.$_classToUse.'" not valid.');
			return false;
		}
		
		/**
		 * @return	string
		 */
		public static function RootPath()
		{
			static $_path = null;
			if (null === $_path)
			{
				$_path = dirname(__FILE__).'/';
			}
			
			return $_path;
		}
		
		/**
		 * @param string $errorDesc
		 */
		private static function _coreError($_errorDesc)
		{
			exit(
'<html>
	<body style="font: normal 13px tahoma, arial; color: black; background: #ccc;">
		<div style="border: solid 1px #5b86a8; margin: 5px; padding: 5px; background: #ffffe1;">
			<font color="red">
				<b>CoreProject:</b>
			</font>
			'.$_errorDesc.'
		</div>
	</body>
</html>');
			
		}
		
		/**
		 * @return	string
		 */
		public static function Name()
		{
			return self::NAME;
		}
		
		/**
		 * @return	string
		 */
		public static function Version()
		{
			return self::VERSION;
		}
		
		/**
		 * @return	string
		 */
		public static function FullName()
		{
			return self::NAME.' ver. '.self::VERSION;
		}
	}
	
	/**
	 * @param	string	$_className
	 *
	function __autoload($_className)
	{
		if (strlen($_className) > 4 && substr($_className, 0, 4) == 'cpr_')
		{
			$_className = substr($_className, 4);
			$_className = str_replace('_', '.', strtolower($_className));
			CoreProject::Using($_className);
		}
	}
	/**/
